#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>

using namespace std;

class Marketing {
public:
	long long howMany(vector <string>);
	bool dfs(int x, int);
	bool grid[31][31];
	int type[31];
	int N;
};

bool Marketing::dfs(int x, int b){
	if(type[x] >= 0) return type[x] == b;
	type[x] = b;
	for(int i=0; i<N; i++){
		if(grid[x][i] && dfs(i, 1-b)==false)
			return false;
	}
	return true;
}

long long Marketing::howMany(vector <string> compete) {
	memset(grid, false, sizeof(grid));
	memset(type, -1, sizeof(type));
	N = compete.size();
	for(int i=0; i<N; i++){
		stringstream s(compete[i]);
		int num;
		while(s >> num){
			grid[i][num] = true;
			grid[num][i] = true;
		}
	}
	long long ret = 1LL;
	for(int i=0; i<N; i++){
		if(type[i] < 0){
//			type[i] = 0;
			ret <<= 1;
			if(dfs(i, 0)==false) return -1;
		}
	}
	return ret;
}


double test0() {
	string t0[] = {"1 4","2","3","0",""};
	vector <string> p0(t0, t0+sizeof(t0)/sizeof(string));
	Marketing * obj = new Marketing();
	clock_t start = clock();
	long long my_answer = obj->howMany(p0);
	clock_t end = clock();
	delete obj;
	cout <<"Time: " <<(double)(end-start)/CLOCKS_PER_SEC <<" seconds" <<endl;
	long long p1 = 2LL;
	cout <<"Desired answer: " <<endl;
	cout <<"\t" << p1 <<endl;
	cout <<"Your answer: " <<endl;
	cout <<"\t" << my_answer <<endl;
	if (p1 != my_answer) {
		cout <<"DOESN'T MATCH!!!!" <<endl <<endl;
		return -1;
	}
	else {
		cout <<"Match :-)" <<endl <<endl;
		return (double)(end-start)/CLOCKS_PER_SEC;
	}
}
double test1() {
	string t0[] = {"1","2","0"};
	vector <string> p0(t0, t0+sizeof(t0)/sizeof(string));
	Marketing * obj = new Marketing();
	clock_t start = clock();
	long long my_answer = obj->howMany(p0);
	clock_t end = clock();
	delete obj;
	cout <<"Time: " <<(double)(end-start)/CLOCKS_PER_SEC <<" seconds" <<endl;
	long long p1 = -1LL;
	cout <<"Desired answer: " <<endl;
	cout <<"\t" << p1 <<endl;
	cout <<"Your answer: " <<endl;
	cout <<"\t" << my_answer <<endl;
	if (p1 != my_answer) {
		cout <<"DOESN'T MATCH!!!!" <<endl <<endl;
		return -1;
	}
	else {
		cout <<"Match :-)" <<endl <<endl;
		return (double)(end-start)/CLOCKS_PER_SEC;
	}
}
double test2() {
	string t0[] = {"1","2","3","0","0 5","1"};
	vector <string> p0(t0, t0+sizeof(t0)/sizeof(string));
	Marketing * obj = new Marketing();
	clock_t start = clock();
	long long my_answer = obj->howMany(p0);
	clock_t end = clock();
	delete obj;
	cout <<"Time: " <<(double)(end-start)/CLOCKS_PER_SEC <<" seconds" <<endl;
	long long p1 = 2LL;
	cout <<"Desired answer: " <<endl;
	cout <<"\t" << p1 <<endl;
	cout <<"Your answer: " <<endl;
	cout <<"\t" << my_answer <<endl;
	if (p1 != my_answer) {
		cout <<"DOESN'T MATCH!!!!" <<endl <<endl;
		return -1;
	}
	else {
		cout <<"Match :-)" <<endl <<endl;
		return (double)(end-start)/CLOCKS_PER_SEC;
	}
}
double test3() {
	string t0[] = {"","","","","","","","","","",
 "","","","","","","","","","",
 "","","","","","","","","",""};
	vector <string> p0(t0, t0+sizeof(t0)/sizeof(string));
	Marketing * obj = new Marketing();
	clock_t start = clock();
	long long my_answer = obj->howMany(p0);
	clock_t end = clock();
	delete obj;
	cout <<"Time: " <<(double)(end-start)/CLOCKS_PER_SEC <<" seconds" <<endl;
	long long p1 = 1073741824LL;
	cout <<"Desired answer: " <<endl;
	cout <<"\t" << p1 <<endl;
	cout <<"Your answer: " <<endl;
	cout <<"\t" << my_answer <<endl;
	if (p1 != my_answer) {
		cout <<"DOESN'T MATCH!!!!" <<endl <<endl;
		return -1;
	}
	else {
		cout <<"Match :-)" <<endl <<endl;
		return (double)(end-start)/CLOCKS_PER_SEC;
	}
}
double test4() {
	string t0[] = {"1","2","3","0","5","6","4"};
	vector <string> p0(t0, t0+sizeof(t0)/sizeof(string));
	Marketing * obj = new Marketing();
	clock_t start = clock();
	long long my_answer = obj->howMany(p0);
	clock_t end = clock();
	delete obj;
	cout <<"Time: " <<(double)(end-start)/CLOCKS_PER_SEC <<" seconds" <<endl;
	long long p1 = -1LL;
	cout <<"Desired answer: " <<endl;
	cout <<"\t" << p1 <<endl;
	cout <<"Your answer: " <<endl;
	cout <<"\t" << my_answer <<endl;
	if (p1 != my_answer) {
		cout <<"DOESN'T MATCH!!!!" <<endl <<endl;
		return -1;
	}
	else {
		cout <<"Match :-)" <<endl <<endl;
		return (double)(end-start)/CLOCKS_PER_SEC;
	}
}

int main() {
	int time;
	bool errors = false;
	
	time = test0();
	if (time < 0)
		errors = true;
	
	time = test1();
	if (time < 0)
		errors = true;
	
	time = test2();
	if (time < 0)
		errors = true;
	
	time = test3();
	if (time < 0)
		errors = true;
	
	time = test4();
	if (time < 0)
		errors = true;
	
	if (!errors)
		cout <<"You're a stud (at least on the example cases)!" <<endl;
	else
		cout <<"Some of the test cases had errors." <<endl;
}

//Powered by [KawigiEdit] 2.0!
